package server

import (
	"company_website/src/global"
	"company_website/src/middleware"
	router2 "company_website/src/router"
	"github.com/gin-gonic/gin"
	"net/http"
)

func InitRouters() *gin.Engine {
	router := gin.Default()
	router.StaticFS(global.GVL_CFG.Local.HeadUrl, http.Dir(global.GVL_CFG.Local.HeadUrl))   // 为用户头像和文件提供静态地址
	router.StaticFS(global.GVL_CFG.Local.TopicUrl, http.Dir(global.GVL_CFG.Local.TopicUrl)) // 为话题图像提供静态地址
	global.GVL_LOG.Info("use middleware logger")

	// 跨域
	router.Use(middleware.Cors()) // 如需跨域可以打开
	global.GVL_LOG.Info("use middleware cors")
	// 健康监测
	router.GET("/health", func(c *gin.Context) {
		c.JSON(200, "ok")
	})
	//个人中心
	adminUser := router.Group("")
	{
		router2.CommonRouter.InitRouter(adminUser)
	}

	admin := router.Group("admin")
	{
		router2.AdminRouter.InitRouter(admin)
		router2.ClientRouter.InitRouter(admin)
		router2.ItemRouter.InitRouter(admin)
	}
	//新闻咨询
	newGroup := router.Group("/")
	{
		router2.GetNewListRouter.InitRouter(newGroup)
	}
	//知识分享
	topic := router.Group("topic")
	{
		router2.TopicRouter.InitRouter(topic)
	}

	return router
}
